package com.gict.antifraudback.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpRequestExample {
    public static void main(String[] args) throws IOException {
        // 请求的URL
        String url = "https://cdn.btlm.top:65533/s?word=T%E5%85%88%E7%94%9F";

        // 创建URL对象
        URL obj = new URL(url);

        // 打开连接
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        // 设置请求方法为GET
        con.setRequestMethod("GET");

        // 设置请求头
        con.setRequestProperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
        con.setRequestProperty("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
        con.setRequestProperty("priority", "u=0, i");
        con.setRequestProperty("sec-ch-ua", "\"Chromium\";v=\"124\", \"Microsoft Edge\";v=\"124\", \"Not-A.Brand\";v=\"99\"");
        con.setRequestProperty("sec-ch-ua-mobile", "?0");
        con.setRequestProperty("sec-ch-ua-platform", "\"Windows\"");
        con.setRequestProperty("sec-fetch-dest", "iframe");
        con.setRequestProperty("sec-fetch-mode", "navigate");
        con.setRequestProperty("sec-fetch-site", "same-origin");
        con.setRequestProperty("sec-fetch-user", "?1");
        con.setRequestProperty("upgrade-insecure-requests", "1");
        con.setRequestProperty("Referer", "https://cdn.btlm.top:65533/s?word=%E6%82%A0%E4%BA%9A");

        // 发送GET请求
        int responseCode = con.getResponseCode();
        System.out.println("Response Code: " + responseCode);

        // 读取响应内容
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuilder response = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        // 打印响应内容
        System.out.println("Response Content:");
        System.out.println(response.toString());
    }
}
